﻿@model DomainModel.Entities.Picture

<script type="text/javascript">

    function checkFileExtension(elem) {
        var filePath = elem.value;

        if (filePath.indexOf('.') == -1)
            return false;

        var validExtensions = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

        validExtensions[0] = 'jpg';
        validExtensions[1] = 'jpeg';
        validExtensions[2] = 'bmp';
        validExtensions[3] = 'png';
        validExtensions[4] = 'gif';


        for (var i = 0; i < validExtensions.length; i++) {
            if (ext == validExtensions[i])
                return true;
        }

        alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');
        elem.value = "";
        return false;
    }
</script>

@using (Html.BeginForm("Create", "Picture", FormMethod.Post, new { enctype = "multipart/form-data" }))

{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Picture</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>
     
    <div class="editor-field">
        <input type="file" name="pictureFile" id="pictureFile" value="Browse" onchange="return checkFileExtension(this);" />
    </div>
     </fieldset>  
}
